package com.huanuo.internetofthings.service.jasperSimStatistics.statisitics;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.unicorn.framework.core.ResponseDto;
import org.unicorn.framework.core.exception.PendingException;

import com.huanuo.internetofthings.bo.jasperSimStatistics.JasperSimStatistics;
import com.huanuo.internetofthings.bo.user.UserInfo;
import com.huanuo.internetofthings.dto.statistics.JasperStatisticsReqDto;
import com.huanuo.internetofthings.enums.JasperSimStatisticsType;
/**
 * 统计设备组Sim卡每月流量共享池总使用情况
 * @author xiebin
 *
 */
@Service
public class JasperSimFlowShareRateStatisticsService extends AbstractJasperSimStatisticsService {

	@Override
	public JasperSimStatistics getJasperSimStatistics(UserInfo userInfo) throws PendingException {
		JasperSimStatistics jasperSimStatistics = new JasperSimStatistics();
		jasperSimStatistics.setGroupNo(userInfo.getGroupNo());
		int year = getYear();
		jasperSimStatistics.setYear(year);
		return jasperSimStatistics;
	}

	@Override
	public ResponseDto<?> calculationStatistics(List<JasperSimStatistics> statisticsList,UserInfo userInfo)
			throws PendingException {
		Map<Integer,Double> map=getSortMap(Double.class);
		for (int m = 1; m <= 12; m++) {
			map.put(m, 0d);
		}
		statisticsList.forEach(jasperSimStatistics->{
			map.put(jasperSimStatistics.getMonth(), jasperSimStatistics.getMonthlyFlowShareRate());
		});
		return new ResponseDto<>(map);
	}




	@Override
	public boolean supports(JasperStatisticsReqDto s) throws PendingException {
		return JasperSimStatisticsType.JasperSim_Total_Flow_Share_Rate_Month_Distribution.equals(s.getJasperSimStatisticsType());
		
	}

}